package com.neutech.controller;

import com.neutech.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class DrugController {
    @Autowired
    private DrugService drugService;
    @RequestMapping("/querydrug")
    @ResponseBody
    public List<Map<String ,Object>> queryDrugByName(@RequestParam Map map)
    {
        List<Map<String ,Object>> list = drugService.queryDrugByName(map.get("name").toString());
        System.out.println(list);
        return drugService.queryDrugByName(map.get("name").toString());
    }

    @ResponseBody
    @RequestMapping("alldrug")
    public List<Map<String, Object>> queryalldrug()
    {
        return drugService.querydruglist();
    }

    @ResponseBody
    @RequestMapping("/codedrug")
    public List<Map<String, Object>> drugbycode(@RequestParam Map map)
    {
        List<Map<String, Object>> list = drugService.querydrugcode(Integer.parseInt(map.get("code").toString()));
        return drugService.querydrugcode(Integer.parseInt(map.get("code").toString()));
    }

    @ResponseBody
    @RequestMapping("/deldrug")
    public void deldrug(@RequestParam Map map)
    {
        System.out.println(map.get("code"));
        drugService.deldrug(Integer.parseInt(map.get("code").toString()));

    }

    @ResponseBody
    @RequestMapping("/adddrug")
    public void adddrug(@RequestParam Map map)
    {
        for (Object key : map.keySet()) {
            String value = (String)map.get(key);

            System.out.println(key + " : " + value);

        }
        drugService.adddrug(map);
    }
}
